<?php

namespace App\Common\Listener;

use App\Common\Util\TP;
use Composer\Autoload\ClassLoader;
use think\facade\App;

/**
 * Class PluginsProxyListener
 */
class PluginsProxyListener
{

    /**
     * Handle the Event when the event is triggered, all listeners will
     * complete before the event is returned to the EventDispatcher.
     */
    public function handle(): void
    {
        $loaders = ClassLoader::getRegisteredLoaders();
        if ($proxy = TP::config('plugins.proxy')) {
            current($loaders)->addClassMap(array_map(fn($path) => App::getRootPath() . $path, $proxy));
        }
    }
}